package com.linwen.excise.leetcode;

import com.linwen.excise.sort.Sortutil;

import java.util.Arrays;

/**
 * @ClassName _75颜色分类
 * @Description
 * @Author zero
 * @DATE 2024/8/12 11:29 PM
 * @Version 1.0
 */
public class _75颜色分类 {
    public static void main(String[] args) {
        _75颜色分类 inst = new _75颜色分类();
        int[] arr = new int[]{2,0,2,1,1,0};
        inst.sortColors(arr);
        Arrays.stream(arr).forEach(System.out::println);
    }
// 双指针问题，快排基础
    public void sortColors(int[] nums) {
        int pivot = 1;
        int left = 0;
        int right = nums.length - 1;
        for (int i = 0; i <= right; i++) {
            if(nums[i]<pivot){
                Sortutil.swap(nums, i, left);
                left++;
            }else if(nums[i]>pivot){
                Sortutil.swap(nums, i, right);
                right--;
                i--;
            }
        }
    }
}
